/**
 * Created by root on 19-12-3.
 * 绘制三维冰锤
 */

#ifndef OPENGLESPRO_GAME_STEP_7_H
#define OPENGLESPRO_GAME_STEP_7_H

#include <cmath>

/**
 * @param radius 圆点半径
 * @param ret 接收返回顶点的数组
 * @param numPoint 除了圆点之外的顶点个数
 * @param x 圆点x
 * @param y 圆点y
 * @param z 圆点z
 * @return
 */
float *circleVertexPosition(float radius, float *ret, int numPoint = 32,
                            float x = 0, float y = 0, float z = 0) {
    int index = -1;
    ret[++index] = x;
    ret[++index] = y;
    ret[++index] = z;
    for (int i = 0; i < numPoint; ++i) {
        float radian = ((float) i / (float) numPoint) * PI * 2;
        ret[++index] = x + radius * cos(radian);
        ret[++index] = y + radius * sin(radian);
        ret[++index] = z;
    }
    ret[++index] = ret[3];
    ret[++index] = ret[4];
    ret[++index] = ret[5];
    return ret;
}

void OnSurfaceCreatedV7();

void OnSurfaceCreatedV7() {}

void OnSurfaceChangedV7();

void OnSurfaceChangedV7() {}

void OnDrawFrameV7();

void OnDrawFrameV7() {
    float vertex[3 * 34] = {};
    circleVertexPosition(0.5f, vertex);
    glEnableVertexAttribArray(0);
    glUniform1f(glGetUniformLocation(device.program, "width"), device.width);
    glUniform1f(glGetUniformLocation(device.program, "height"), device.height);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertex);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 34);
    glDisableVertexAttribArray(0);
}

#endif //OPENGLESPRO_GAME_STEP_7_H
